package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.indexchangerecord.LindiIndexChangeRecordQueryVO;
import com.minimalist.common.entity.lindi.vo.indexchangerecord.LindiIndexChangeRecordVO;
import com.minimalist.common.feign.client.lindi.LindiIndexChangeRecordFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 林地指标变更记录Feign客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author minimalist
 */
@Component
public class LindiIndexChangeRecordFeignClientFallbackFactory extends BaseFallbackFactory<LindiIndexChangeRecordFeignClient> {
    private static final Logger log = LoggerFactory.getLogger(LindiIndexChangeRecordFeignClientFallbackFactory.class);


    @Override
    public LindiIndexChangeRecordFeignClient create(Throwable cause) {
        return new LindiIndexChangeRecordFeignClient() {
            @Override
            public R<?> addIndexChangeRecord(LindiIndexChangeRecordVO recordVO) {
                logServiceUnavailable("添加指标变更记录", recordVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "添加指标变更记录失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteIndexChangeRecordByIndexChangeRecordId(Long indexChangeRecordId) {
                logServiceUnavailable("删除指标变更记录", indexChangeRecordId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "删除指标变更记录失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updateIndexChangeRecordByIndexChangeRecordId(LindiIndexChangeRecordVO recordVO) {
                logServiceUnavailable("修改指标变更记录", recordVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "修改指标变更记录失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiIndexChangeRecordVO>> getPageIndexChangeRecordList(LindiIndexChangeRecordQueryVO queryVO) {
                logServiceUnavailable("分页查询指标变更记录列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "分页查询指标变更记录列表失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiIndexChangeRecordVO> getIndexChangeRecordByIndexChangeRecordId(Long indexChangeRecordId) {
                logServiceUnavailable("获取指标变更记录详情", indexChangeRecordId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "获取指标变更记录详情失败，服务不可用: " + cause.getMessage());
            }
        };
    }
}
